package work.display
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	
	/**
	 * 加载完成初始化事件 
	 * @eventType flash.events.Event.INIT
	 */
	[Bindable]
	[Event(name="init", type="flash.events.Event")]
	
	public class LoadEFCDisplay extends LoadEFC
	{
		public static const CONTENT_TYPE_SWF:String="swf";
		public static const CONTENT_TYPE_JPEG:String="jpeg";
		public static const CONTENT_TYPE_GIF:String="gif";
		public static const CONTENT_TYPE_PNG:String="png";
		
		protected var _content:DisplayObject;
		protected var _contentType:String;
		public function LoadEFCDisplay()
		{
			super();
		}
		/**
		 * 获得内容的类型 ，必须在加载完成后才能获取该值
		 * @return 
		 * 
		 */
		public function get contentType():String
		{
			return _contentType;
		}
		
		/**
		 * 获得加载完成后的内容 
		 * @return 
		 * 
		 */
		public function get content():DisplayObject
		{
			return _content;
		}
		override protected function loadContent():void
		{
			super.loadContent();
			var loader:Loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.INIT,onLoaderInitEvent);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onErrorEvent);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onPressEvent);
			loader.loadBytes(contentData);
			
		}
		private function onLoaderInitEvent(e:Event):void
		{
			var loadinfo:LoaderInfo=LoaderInfo(e.target);
			_content=loadinfo.content;
			switch(loadinfo.contentType)
			{
				case "application/x-shockwave-flash":
					_contentType="swf";
					break;
				case "image/jpeg":
					_contentType="jpeg";
					break;
				case "image/gif":
					_contentType="gif";
					break;
				case "image/png":
					_contentType="png";
					break;				
			}
			//_contentData.clear();
			this.dispatchEvent(new Event(Event.INIT));
		}
		
		private function checkIsEfc(uri:String):Boolean
		{
			//var s:String=uri.toLocaleLowerCase();
			var arr:Array=uri.split(".");
			var s:String=arr.pop();
			s=s.toLocaleLowerCase();
			if(s!="efc")
			{
				return false;
			}
			return true;
		}
	}
}